<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页展示</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="../../res/layuis/dist/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../res/layuis/dist/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 body{margin: 10px;} -->
    <script src="../../res/js/login_common.js" charset="UTF-8"></script>
    <style>

        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}

        *{margin:0;padding:0;}

        html,body{
            height:100%;
            overflow-x: hidden;
        }

        #tableDiv{
            width: 100%;
            height: 100%;
            border: solid 0px #0C0C0C;
        }

        .tableTest{
            width: 50%;
            float: left;
            overflow: hidden;
            border: solid 0px #0C0C0C;
        }



    </style>


</head>
<body>
<div id="tableDiv">

    <div id="table1" class="tableTest" >
        <table class="layui-hide" id="demo1" lay-filter="test"></table>
    </div>
    <div id="table2" class="tableTest">
        <table class="layui-hide" id="demo2" lay-filter="test"></table>
    </div>
    <div id="table3" class="tableTest">
        <table class="layui-hide" id="demo3" lay-filter="test"></table>
    </div>
    <div id="table4" class="tableTest">
        <table class="layui-hide" id="demo4" lay-filter="test"></table>
    </div>

</div>




<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">浏览</a>
</script>
<script type="text/html" id="toolbarDemo1">
    <div style="width: 216px; margin: 0;">
        <button type="button" onclick="openPage(1)" class="layui-btn layui-btn-fluid">通知公告</button>
    </div>
</script>

<script type="text/html" id="toolbarDemo2">
    <div style="width: 216px; margin: 0;">
        <button type="button" onclick="openPage(2)" class="layui-btn layui-btn-fluid">公务信息</button>
    </div>
</script>

<script type="text/html" id="toolbarDemo3">
    <div style="width: 216px; margin: 0;">
        <button type="button" onclick="openPage(3)"  class="layui-btn layui-btn-fluid">文件政策</button>
    </div>
</script>

<script type="text/html" id="toolbarDemo4">
    <div style="width: 216px; margin: 0;">
        <button type="button" onclick="openPage(4)"  class="layui-btn layui-btn-fluid">学习资料</button>
    </div>
</script>


<script>

    layui.config({
        version: '1572350921010' //为了更新 js 缓存，可忽略
    });

    function openPage(obj) {
        var attachSrc = {};
        attachSrc.attachState = '1';

        if (obj === 1){
            attachSrc.attachType = '通知公告';
            attachSrc.name = '../../../pages/cy/Attachment.html?attachTypeId=10';
        }else if (obj === 2){
            attachSrc.attachType = '公务信息';
            attachSrc.name = '../../../pages/cy/Attachment.html?attachTypeId=20';
        }else if (obj === 3){
            attachSrc.attachType = '文件政策';
            attachSrc.name = '../../../pages/cy/Attachment.html?attachTypeId=30';
        }else if (obj === 4){
            attachSrc.attachType = '学习资料';
            attachSrc.name = '../../../pages/cy/Attachment.html?attachTypeId=40';
        }

        var homePage = window.parent;
        //homePage.attach(attachSrc);
        homePage.zhuan(attachSrc);

    }

    var attachTypeId1 = 10;
    var attachTypeId2 = 20;
    var attachTypeId3 = 30;
    var attachTypeId4 = 40;
    var attachPage = '0';
    var attachLimit = '5';
    layui.use([ 'layer', 'table', 'element', 'laydate','form'], function(){
        var layer = layui.layer //弹层
            ,table = layui.table //表格
            ,element = layui.element //元素操作
            ,form = layui.form
            ,laydate = layui.laydate; //表单



        //监听Tab切换
        element.on('tab(demo)', function(data){
            layer.tips('切换了 '+ data.index +'：'+ this.innerHTML, this, {
                tips: 1
            });
        });
        var userId = window.loginObj.manager.usId;
        var userName = window.loginObj.manager.usName;
        var url = "../../attachment/selectHomePageByUserId";
        //执行一个 table 实例
        table.render({
            elem: '#demo1'
            ,height: 300
            ,even: true //隔行背景
            ,url: url //数据接口
            ,title: '用户表'
            //,page: true //开启分页
            ,toolbar: '#toolbarDemo1' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,defaultToolbar: []
            ,where:{
                attachType:attachTypeId1
                ,userId: userId
                ,userName:userName
                ,page:attachPage
                ,limit:attachLimit
            }
            ,cols: [[ //表头
                {field: 'attachId', title: 'ID', width:60, sort: true, fixed: 'left',hide:true}
                ,{field: 'attachName', title: '标题'}
                ,{field: 'attachTime', title: '发布时间',  sort: true}
                ,{field: 'attachPublisher', title: '发布人'}
                ,{fixed: 'right', width: 80, align:'center', toolbar: '#barDemo'}
            ]]
        });
        table.render({
            elem: '#demo2'
            ,height: 300
            ,even: true //隔行背景
            ,url: url //数据接口
            ,title: '用户表'
            //,page: true //开启分页
            ,toolbar: '#toolbarDemo2' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,defaultToolbar: []
            ,where:{
                attachType:attachTypeId2
                ,userId: userId
                ,userName:userName
                ,page:attachPage
                ,limit:attachLimit
            }
            ,cols: [[ //表头
                {field: 'attachId', title: 'ID', width:60, sort: true, fixed: 'left',hide:true}
                ,{field: 'attachName', title: '标题'}
                ,{field: 'attachTime', title: '发布时间',  sort: true}
                ,{field: 'attachPublisher', title: '发布人'}
                ,{fixed: 'right', width: 80, align:'center', toolbar: '#barDemo'}
            ]]
        });
        table.render({
            elem: '#demo3'
            ,height: 300
            ,even: true //隔行背景
            ,url: url //数据接口
            ,title: '用户表'
            //,page: true //开启分页
            ,toolbar: '#toolbarDemo3' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,defaultToolbar: []
            ,where:{
                attachType:attachTypeId3
                ,userId: userId
                ,userName:userName
                ,page:attachPage
                ,limit:attachLimit
            }
            ,cols: [[ //表头
                {field: 'attachId', title: 'ID', width:60, sort: true, fixed: 'left',hide:true}
                ,{field: 'attachName', title: '标题'}
                ,{field: 'attachTime', title: '发布时间',  sort: true}
                ,{field: 'attachPublisher', title: '发布人'}
                ,{fixed: 'right', width: 80, align:'center', toolbar: '#barDemo'}
            ]]
        });
        table.render({
            elem: '#demo4'
            ,height: 300
            ,even: true //隔行背景
            ,url: url //数据接口
            ,title: '用户表'
            //,page: true //开启分页
            ,toolbar: '#toolbarDemo4' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,defaultToolbar: []
            ,where:{
                attachType:attachTypeId4
                ,userId: userId
                ,userName:userName
                ,page:attachPage
                ,limit:attachLimit
            }
            ,cols: [[ //表头
                {field: 'attachId', title: 'ID', width:60, sort: true, fixed: 'left',hide:true}
                ,{field: 'attachName', title: '标题'}
                ,{field: 'attachTime', title: '发布时间',  sort: true}
                ,{field: 'attachPublisher', title: '发布人'}
                ,{fixed: 'right', width: 80, align:'center', toolbar: '#barDemo'}
            ]]
        });


        //监听行工具事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            var deleteAttachIds = ''; //数组id
            if(layEvent === 'detail'){
                layer.open({
                    type: 2,
                    title : '通知页面',
                    shadeClose : true,
                    shade : 0.8,
                    area : [ '100%', '100%' ],
                    content: 'AttachmentShow.html',
                    success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                        //console.log('============'+iframeWin);
                        body.find("#attachId").val(data.attachId);
                        body.find("#attachType").val(data.attachType);
                        iframeWin.beginShow();
                    },
                    end : function() {
                        //table.reload('demo',{});
                    }
                });
            }
        });

    });


</script>
</body>
</html>